<!--
 * @Description: htm
 * @Author: charles
 * @Date: 2021-06-18 11:57:10
 * @LastEditors: charles
 * @LastEditTime: 2021-06-18 15:06:15
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>threejs</title>
  <style>
    body {
      margin: 0;
    }
  </style>
  <script src="https://cdn.bootcdn.net/ajax/libs/three.js/r128/three.min.js"></script>
</head>
<body>
  <div id="container" style=" margin: 100px auto;"></div>
  <script>
    let container = document.getElementById("container");
    // 创建场景对象Scene
    const scene = new THREE.Scene();
    const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );

    const renderer = new THREE.WebGLRenderer();
    renderer.setSize( window.innerWidth, 400 );
    container.appendChild( renderer.domElement );
    //创建网格模型
    const geometry = new THREE.BoxGeometry();
    const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
    const cube = new THREE.Mesh( geometry, material );
    scene.add( cube );
    // 点光源
    var point = new THREE.PointLight(0xffffff);
    point.position.set(400, 200, 300); //点光源位置
    scene.add(point);

    camera.position.z = 5;

    const animate = function () {
      requestAnimationFrame( animate );
      cube.rotation.x += 0.01;
      cube.rotation.y += 0.01;
      renderer.render( scene, camera );
    };

    animate();
  </script>
</body>
</html>